package com.lzc.springcloud.msconsumeruser.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.lzc.springcloud.msconsumeruser.entity.User;
import com.lzc.springcloud.msconsumeruser.feign.UserFeignClient;

@RestController
public class UserController {
	
	@Autowired
	private UserFeignClient userFeignClient;
	
	@GetMapping("/getUser/{id}")
	public User getUser(@PathVariable Integer id) {
		
		return this.userFeignClient.getUser(id);
	}
	
	@GetMapping("/getUserInfo/{id}")
	public User getUserInfo(@PathVariable Integer id) {
		User user = new User();
		user.setId(id);
		user.setName("UserInfo");
		return this.userFeignClient.getUserInfo(user);
	}
	
	@GetMapping("/list-all")
	public List<User> listAll() {
	    // wrong
//		List<User> list = this.restTemplate.getForObject("http://microservice-provider-user/list-all", List.class);
//		for (User user : list) {
//			System.out.println(user.getId());
//		}

	    // right
//	    User[] users = this.restTemplate.getForObject("http://microservice-provider-user/list-all", User[].class);
//	    List<User> list2 = Arrays.asList(users);
//	    for (User user : list2) {
//	      System.out.println(user.getId());
//	    }

	    return null;
	}
}
